$('.right-titleicon').on("click",function(e){
	projectVM.showMenulist()
})
let that;
projectVM = new Vue({
	el: "#content",
	components:{ 
		personselect
	},
	data: {
		isSearch:0,//是否为综合查询进来的 0 否 1 是
		mType:"0",//当前页面 所需要表现的功能：0 录入 1 展示 2编辑修改
		isSingle:false,
		showSelect:false,
		isEdittext:true, //true 不可编辑 false 可以编辑
		menuList:[
			{name:'新增',path:'add.html'},{name:'列表',path:'index.html'},
		],
		typeList:[],//变压器类型list
		typeConnseList:{},//已选择的变压器类型
		showSubmit:false,
		onStatus:'',
		selectText:'请选择	',
		result:'',
		showMenu:false,
		showMorebtn:false,
		advance:'',
		showAdd:false,
		show_popup:false,
		addTransformerList:[],//做添加操作时候的变压器list
		persionInfor:{},//上个页面传过来的人员信息
		list:[{content:'XXX信用XXXX钥匙',status:1,user:'[IP123456]张三2021-6-20'},
		{content:'XXX信用XXXX钥匙',status:2,user:'[IP123456]张三2021-6-20'},
		{content:'XXX信用XXXX钥匙',status:3,user:'[IP123456]张三2021-6-20'}],
		infoListParam:[{
			isLumpFirst:false,
			isLumpFirstAdd:true,
			selectText:"请选择变压器",
			transType:"",
			transTypeText:"",
			deviceCode:"",
			beforeAdjustInfo:"",
			afterAdjustInfo:"",
			operateCount:"",
			beforeI:"",
			afterI:"",
			highV:"",
			lowV:"",
			beforeHighV:"",
			afterHighV:"",
			beforeLowV:"",
			afterLowV:"",
			remark:"",
		}],//变压器子表数据
		transConfig:{},//通用COnfig
		paramData:{},//上传用的总表数据
		isExit:true,//当前页面是否可以编辑 true 可以 false 不可编辑
		tutelageStaffName:"",//监护人
		operateName:"",
		pageType:"3",//页面类型 1 办理（带有编辑/详情）0 详情 均不可编辑 100 新增
		transTypeOne:"", //人员信息数据
		transFormDate:"",//变压器单日期
		persionName:"",
	},
	created: function() {
		that = this;
		// that.getUserInfo();
		setTimeout(that.getTransformerType,500)
		setTimeout(that.getPageParam,800);
	},
	methods: {
		//获取页面传值 （因为没有Plus环境）
		getPageParam(){
			
			let config = mui.neioConfig.getNeioConfig();
			let pageKey = config.KEYS.PAGE_PARAM_TRANSFORM_INFO;
			let dataParam = mui.neioConfig.getStorage(pageKey)
			if("" == dataParam){
				return;
			}
			let paramJson = JSON.parse(dataParam);
			console.log(dataParam)
			that.isEdittext = (paramJson.mType == '0' || paramJson.mType == '2') ? false :  true;//默认false 可编辑
			that.isSearch = paramJson.isSearch == '1' ? paramJson.isSearch : '0';
			debugger
			that.pageType = paramJson.mType;
			if(paramJson.mType == "0"){
				if(paramJson.tutelageStaffCodeName != "" && paramJson.tutelageStaffCodeName != undefined){
					that.persionName = paramJson.tutelageStaffCodeName;
					this.$nextTick(this.$refs.personselect.person = paramJson.tutelageStaffCodeName)
					this.$nextTick(this.$refs.personselect.personids = paramJson.tutelageStaffCode)
				}
			}
			if(paramJson.mType == "1"){
				//详情
				if('1' == paramJson.isSearch){
					that.tutelageStaffName = '['+paramJson.tutelageStaffCode+']'+paramJson.tutelageStaffName;
					that.operateName = '['+paramJson.operateStaffCode+']'+paramJson.operateStaffName;
				}
				that.transFormDate = paramJson.data[paramJson.position].operateDate;
				let array = []
				array.push(paramJson.data[paramJson.position])
				that.transTypeOne = paramJson.data[paramJson.position].transType;
				//设置基 人员信息数据
				that.infoListParam = array;
				that.getTransFormType(that.transTypeOne);
			}
			
			if(paramJson.mType == "2"){
				//编辑
				if(undefined != paramJson.data){
					that.addTransformerList = paramJson.data;
					
					that.persionInfor.operateStaffCode = paramJson.data[0].operateStaffCode;
					that.persionInfor.operateStaffCodeName = '['+paramJson.data[0].operateStaffCode+']'+paramJson.data[0].operateStaffName;
					that.persionInfor.operateStaffName = paramJson.data[0].operateStaffName
					
					if(undefined != paramJson.data[0].tutelageStaffCode){
						that.persionInfor.tutelageStaffCode = paramJson.data[0].tutelageStaffCode;
						that.persionInfor.tutelageStaffName = paramJson.data[0].tutelageStaffName;
						that.persionInfor.tutelageStaffCodeName = '['+paramJson.data[0].tutelageStaffCode+']' + paramJson.data[0].tutelageStaffName
					}else{
						that.persionInfor.tutelageStaffCode = paramJson.data[0].tutelageStaffCodeName.split(']')[0].split('[')[1];
						that.persionInfor.tutelageStaffName = paramJson.data[0].tutelageStaffCodeName.split(']')[1];
						that.persionInfor.tutelageStaffCodeName = '['+paramJson.data[0].tutelageStaffCode+']' + paramJson.data[0].tutelageStaffName
					}
					that.persionInfor.workId = paramJson.data[0].workId;
					
				}
				that.transFormDate = paramJson.data[paramJson.position].operateDate;
				let array = []
				array.push(paramJson.data[paramJson.position])
				that.transTypeOne = paramJson.data[paramJson.position].transType;
				
				//显示人员信息
				that.persionName = that.persionInfor.tutelageStaffCodeName;
				that.$nextTick(that.$refs.personselect.person = that.persionInfor.tutelageStaffCodeName)
				that.$nextTick(that.$refs.personselect.personids = that.persionInfor.tutelageStaffCode)
				//设置基 人员信息数据
				that.infoListParam = array;
				that.getTransFormType(that.transTypeOne);
			}
			
			//======================================================
		
			return;
			that.pageType = paramJson.pageType;
			if('9' == paramJson.pageType || '0' == paramJson.pageType){
				//设置状态为不可编辑
				that.isEdittext = true;
			}
			if('100' == that.pageType || '200' == that.pageType){
				if(undefined != paramJson.data){
					
					that.addTransformerList = paramJson.data;
					
					that.persionInfor.operateStaffCode = paramJson.data[0].operateStaffCode;
					that.persionInfor.operateStaffCodeName = '['+paramJson.data[0].operateStaffCode+']'+paramJson.data[0].operateStaffName;
					that.persionInfor.operateStaffName = paramJson.data[0].operateStaffName
					
					that.persionInfor.tutelageStaffCode = paramJson.data[0].tutelageStaffCode;
					that.persionInfor.tutelageStaffName = paramJson.data[0].tutelageStaffName;
					that.persionInfor.tutelageStaffCodeName = '['+paramJson.data[0].tutelageStaffCode+']' + paramJson.data[0].tutelageStaffName
					that.persionInfor.workId = paramJson.data[0].workId;
					
				}
				// return;
			}
			that.transFormDate = paramJson.data[paramJson.position].operateDate;
			let array = []
			array.push(paramJson.data[paramJson.position])
			that.transTypeOne = paramJson.data[paramJson.position].transType;
			debugger
			if('10' != paramJson.type){
				that.infoListParam = array;
				that.getTransFormType(that.transTypeOne);
			}
		},
		getTransFormType(code,array){
			let transFormTypeList = mui.neioConfig.getTransFormer();
			console.log("获取变压器类型："+ transFormTypeList)
			if(null == transFormTypeList) return
			let type = mui.neiosCommon.dictTransform(JSON.parse(transFormTypeList),code);

			that.infoListParam[0].selectText = type;
			that.infoListParam[0].transTypeText = type;
			that.infoListParam[0].isLumpFirst = false;
			that.infoListParam[0].isLumpFirstAdd = true;
			that.selectText = type;
			//设置默认监护人
			// this.$nextTick(this.$refs.personselect.person = that.addTransformerList[0].tutelageStaffCodeName)
			// this.$nextTick(this.$refs.personselect.personids = that.addTransformerList[0].tutelageStaffCode)
		},
		uuidv4() {
			let uuid = mui.neiosCommon.getUuidv4();
			return uuid;
		},
		//选择变压器类型
		chooseType(e,position){
			console.log(JSON.stringify())
			that.infoListParam[position].selectText = e.itemText;
			that.infoListParam[position].transType = e.itemValue;
			that.infoListParam[position].transTypeText = e.itemText;
			that.selectText = e.itemText;
			that.typeConnseList = e;
			// that.createPushData();
		},
		//获取用户信息 -- 之后删除
		getUserInfo(){
			mui.neiosCommon.getUserInfo(function(ret){})
		},
		//初始化变压器类型
		getTransformerType(){
			//获取变压器类型
			let transFormertype = mui.neioConfig.getTransFormer();
			//存入变压器类型List
			that.typeList = JSON.parse(transFormertype)
		},
		//组装上传的数据(主表)
		createPushData(){
			let paramData = {};
			paramData.transForm = {};//数据中最外层的人员组织信息
			paramData.infoListParam = [];//内部表单List
			//人员信息 获取
			let persionData = JSON.parse(localStorage.getItem("neiosUser"));
			
			//如果上个页面有传过来数据 就使用
			if(that.addTransformerList.length > 0){
				//当前由变压器子表数据为条件-生成N 个对象（主表加子表）
				let infoListArray = {};
				that.infoListParam.forEach((item,i)=>{
					//字表数据 和 传过来的数据结合成新的 OBJ
					let dataObj = {};
					//获取穿过来数据的第0个 （因为只是使用对象里公共的部分字段，所以选那个都一样）
					let formArrayLists = that.addTransformerList[0];
					//字表数据 和 传过来的数据结合，生成主表
					Object.assign(dataObj,formArrayLists,item)
					//如果是从有载调压详情列表（第二列表）进来状态码200的新增 需要为子表设置
					 //type :"add"
					 if(that.pageType == '2'){
						 dataObj.type = "add"
					 }
					//使用结合好的数据 获取完整的 字表加主表的数据
					let datas = mui.neioConfig.getTransForm(dataObj,1,0);
					//将获取的完整的数据（循环后的N条）整理成一个对象
					console.log("参数1："+JSON.stringify(infoListArray))
					console.log("参数2："+JSON.stringify(datas))
					Object.assign(infoListArray,datas)
					if(that.pageType == '2'){
						infoListArray.transForm.type = "edit"
					}
				})
				let mArrray;
				//如果没有新增单据 则不向参数中添加 更多单据
				if(that.infoListParam.length > that.addTransformerList.length){
					//将传过来的数据和整理好的完整的数据的List 合并
					mArrray = infoListArray.infoListParam.concat(that.addTransformerList)
					//合并好的数据 装进完成的数据里 形成新的完整的数据
					infoListArray.infoListParam = mArrray;
				}
				infoListArray.transForm.tutelageStaffCode = this.$refs.personselect == undefined ? that.persionInfor.tutelageStaffCode : this.$refs.personselect.personids;//监护人工号
				infoListArray.transForm.tutelageStaffName = this.$refs.personselect == undefined ? that.persionInfor.tutelageStaffCodeName : this.$refs.personselect.person.split("]")[1];//监护人姓名
				infoListArray.transForm.tutelageStaffCodeName = this.$refs.personselect == undefined ? that.persionInfor.tutelageStaffCodeName : this.$refs.personselect.person;//监护人工号姓名
				 
				infoListArray.transForm.operateStaffCode = that.persionInfor.operateStaffCode;
				infoListArray.transForm.operateStaffCodeName = that.persionInfor.operateStaffCodeName;
				infoListArray.transForm.operateStaffName = that.persionInfor.operateStaffName;
				paramData = infoListArray;
			}else{
				paramData.transForm.status = "21"; //状态 固定传21
				paramData.transForm.operateStaffCodeName = persionData.userName;//操作人工号姓名-当前人
				paramData.transForm.operateStaffCode = persionData.userId;//操作人工号
				paramData.transForm.operateStaffName = persionData.name;//操作人姓名
				paramData.transForm.tutelageStaffCode = this.$refs.personselect.personids;//监护人工号
				paramData.transForm.tutelageStaffName = this.$refs.personselect.person.split("]")[1];//监护人姓名
				paramData.transForm.tutelageStaffCodeName = this.$refs.personselect.person;//监护人工号姓名
				paramData.transForm.transOperateId = that.uuidv4();//主键Id
				paramData.transForm.type = "add";//如果是新增数据就不传，如果是编辑数据就传edit
				paramData.transForm.modifyBy = persionData.userId;//当前登陆人工号
				paramData.transForm.modifyStaffName = persionData.name;//当前登录人姓名
				paramData.transForm.areaCompanyCode = persionData.companyCode;//分公司编码--新增时候传，编辑不传
				paramData.transForm.stationCode = persionData.stationCode;//场站编码--新增时候传，编辑不传
				paramData.transForm.dataStatus = "1";////数据状态1有效0无效
				paramData.transForm.dataSource = "NEIOS_APP"+localStorage.getItem("currVersion");//固定值--新增时候传，编辑不传
				paramData.transForm.client = "NEIOS";//固定值--新增时候传，编辑不传
				paramData.transForm.createBy = persionData.userId;//当前登录人编号--新增时候传，编辑不传
				paramData.transForm.createStaffName = persionData.name;//当前登陆人姓名--新增时候传，编辑不传
				paramData.transForm.newAreaCode  = persionData.companyNewCode;//新能源分公司编码
				paramData.transForm.newStationCode  = localStorage.getItem('neiosStationCode') == null ? '1020' : localStorage.getItem('neiosStationCode');//新能源场站编码
				
				that.paramData = paramData;
			
				let childDataItem = that.infoListParam;//填写后产生的数据（list）
				
				let obj = {};
				//参数拼装
				childDataItem.forEach((item,index)=>{
					obj = {};
					let childParams = that.createChildtab();//子表中需要生成的数据
					Object.assign(obj,childParams,item)
					paramData.infoListParam.push(obj)
				})
			}
			
			return paramData;
		}, 
		//子表数据拼装
		createChildtab(){
			let childParam = {};//变压器表（子表）	
			let persionData = JSON.parse(localStorage.getItem("neiosUser"));
			let date = that.dateFormate();
			
			childParam.transOperateInfoId =  that.uuidv4();
			childParam.transOperateId = that.paramData.transForm.transOperateId;//从表Id
			// childParam.transOperateId = that.uuidv4();
			childParam.operateDate = date;//操作日期
			// childParam.transType = that.typeConnseList.itemCode;//变压器类型·
			childParam.client = "NEIOS";//固定值
			childParam.dataSource = "NEIOS_APP"+localStorage.getItem("currVersion");//固定值
			childParam.status = "21";//保存 固定21
			childParam.dataStatus = "1";
			childParam.createBy = persionData.userId;
			childParam.createStaffName = persionData.name;
			childParam.createDate = that.getMiu();//创建时间
			childParam.modifyBy = persionData.userId;
			childParam.modifyStaffName = persionData.name;
			childParam.modifyDate = that.getMiu();//修改时间
			childParam.reserveField1 = null;
			childParam.reserveField2 = null;
			childParam.reserveField3 = null;
			childParam.reserveField4 = null;
			childParam.reserveField5 = null;
			// childParam.transTypeText = that.typeConnseList.itemText;
			
			return childParam;
		},		
		// 获取时间
		dateFormate () {
			return mui.neiosCommon.transTime(new Date(),"min")
		},
		//获取毫秒
		getMiu(){
			let date = that.dateFormate();
			var arr = date.split(/[- : \/]/);
			var startDate = Date.parse(new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4]));
			return startDate;
		},
		//保存或提交表单
		/**
		 * @param {Object} type 1,确认并新增，2,确认并保存
		 */
		saveForm(type){
			// if(that.typeConnseList.itemText == undefined){
			// 	mui.alert("请选择变压器类型");
			// 	return;
			// }
			//非空验证
			let isverification = mui.neioConfig.verificationData(that.infoListParam);
			if(!isverification){
				return;
			}
			
			let message = "是否保存";
			
			mui.confirm(message,'提示',['取消','确认'],function (e) {
				if(1 == e.index){
					//最终组装数据
					let param = that.createPushData()
					param.pageType = that.pageType;
					console.log("---=-=-=-="+JSON.stringify(param))
					let pageId = plus.webview.getWebviewById("procressing.html");
					mui.fire(pageId, 'callBackData', param);
					if('2' == type){
						setTimeout(that.goBack,500);
					}
					// if('1' == type){
					// 	mui.toast("确认并新增")
					// 	let config = mui.neioConfig.getNeioConfig();
					// 	let url = config.URL.saveOrUpdateTransOperate;
					// 	that.pushForm(url,param)
					// 	return;
					// }
					// if(2 == type){
					// 	mui.toast("确认并保存")
					// 	let config = mui.neioConfig.getNeioConfig();
					// 	let url = config.URL.submitTransOperate;
					// 	//定制提交表单的数据
					// 	let comData = that.commitData(param)
					// 	that.pushForm(url,comData)
					// 	return;
					// }
				}
			},'div')
		},
		//提交数据操作
		commitData(param){
			let data = param;
			data.transForm.status = "32";//固定32
			if(that.addTransformerList.length > 0){
				data.transForm.workId = that.persionInfor.workId
			}else{
				data.transForm.workId = that.uuidv4();
			}
			data.transForm.workDesc = "对变压器有载调压信息进行确认"
			data.workType = "0206"
			data.infoListParam.forEach((item,position)=>{
				item.status = "32"
			})
			return data;
		},
		
		//网络操作
		pushForm(url,params){
			mui.neiosRequst.httpRequst(url,params,function(ret){
				if(ret.code == 0){
					mui.toast(ret.msg)
					setTimeout(that.goBack,700);
				}
				if( ret.code == 1){
						mui.toast(ret.msg)
				}
			},function(err){
				console.log("失败回掉："+JSON.stringify(err))
			})
		},
		//返回上一页
		goBack(){
			mui.back()
		},
		//更多按钮
		showMore(){
			this.showMorebtn ? this.showMorebtn = false : this.showMorebtn = true
		},
		//阻止事件冒泡
		clickStop(){

		},
		//选择是否为值班人
		checkOnstatus(){
			this.onStatus ? this.onStatus = false : this.onStatus =true
			
		},
		//点击菜单
		menuClick(e){
			if(e.name == '我值班'){
				this.onStatus? this.onStatus= false : this.onStatus=true
			}else{
				this.navTo(e.path)
			}
		},
		//添加新的检查单
		addLupm(){
			this.infoListParam.forEach( (item,i) =>{
				if(i == 0){
					item.isLumpFirst = true;
					item.isLumpFirstAdd = false;
				}
			})
			let newLumpItem = {
				isLumpFirst:true,
				isLumpFirstAdd:true,
				selectText:"请选择变压器",
				transType:"",
				transTypeText:"",
				deviceCode:"",
				beforeAdjustInfo:"",
				afterAdjustInfo:"",
				operateCount:"",
				beforeI:"",
				afterI:"",
				highV:"",
				lowV:"",
				beforeHighV:"",
				afterHighV:"",
				beforeLowV:"",
				afterLowV:"",
				remark:""
			}
			this.infoListParam.push(newLumpItem)
		},
		//移除检查单
		removeLupm(position){
			this.infoListParam.splice(position,1)
			if(this.infoListParam.length <= 1){
				this.infoListParam[0].isLumpFirst = false;
				this.infoListParam[0].isLumpFirstAdd = true;
			}else{
				let lumpItemPosition = this.infoListParam.length;
				this.infoListParam[lumpItemPosition - 1].isLumpFirstAdd = true;
			}
		},
		//左上角菜单显示隐藏
		showMenulist(){
			this.showMenu?this.showMenu=false:this.showMenu=true
		},
		navTo(e){
			mui.openWindow({
					url: e,
					id: e,
			});
			}
	},
	
	})